from dataaccess import ArtistData
from common import utility,SearchFilter, ArtistEntity

class ArtistBiz(object):
    def __init__(self):
        pass

    def __ValidateInsert(self, artist):
        dups = ArtistData.ArtistData().SelectArtistByFilter(
            SearchFilter.SimpleFilter(ArtistEntity.ArtistEntity.ColumnNames.name,SearchFilter.ConditionType.Equal,artist.Name.strip()))
        if len(dups)>0:
            raise utility.BusinessException(message="An artist with this name already exists.",fieldName = "name")
        
    def __ValidateUpdate(self, artist):
        valid = True
        if not valid:
            raise utility.BusinessException(message="",fieldName = "")
        
    def __ValidateDelete(self, artistID):
        valid = True
        if not valid:
            raise utility.BusinessException(message="",fieldName = "")
        
    def InsertArtist(self, artist):
        self.__ValidateInsert(artist)
        artistData = ArtistData.ArtistData()
        return artistData.InsertArtist(artist)

    def UpdateArtist(self, artist):
        self.__ValidateUpdate(artist)
        artistData = ArtistData.ArtistData()
        artistData.UpdateArtist(artist)

    def DeleteArtist(self, artistID):
        self.__ValidateDelete(artistID)
        artistData = ArtistData.ArtistData()
        artistData.DeleteArtist(artistID)

